﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MYSMRM.Manager.Interface;

namespace MYSMRM.Web.QS
{
    public partial class TopicList : System.Web.UI.Page
    {
        DataTable dt;

        public IQSTopicManager TopicManager { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            InitData();

            gv_Topic.DataSource = dt;
            gv_Topic.DataBind();
        }

        protected void gv_Topic_RowEditing(object sender, GridViewEditEventArgs e)
        {
            DataRow dr = dt.Rows[e.NewEditIndex];
            Response.Redirect("..\\QS\\TopicDetail.aspx?I_ID=" + dr["I_ID"].ToString());
        }

        protected void gv_Topic_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //DataRow dr = dt.Rows[e.RowIndex];
            //#region shine 20130517
            ////string sql1 = "delete from dbo.QS_OPTION where I_TOPIC_ID=" + dr["I_ID"].ToString();
            //TopicManager.ExecuteNonQuery("delete from dbo.QS_OPTION where I_TOPIC_ID=" + dr["I_ID"].ToString());
            //TopicManager.ExecuteNonQuery("delete from dbo.QS_SURVERY where I_TOPIC_ID=" + dr["I_ID"].ToString());
            //TopicManager.ExecuteNonQuery("delete from dbo.QS_TOPIC where I_ID=" + dr["I_ID"].ToString());
            //#endregion
            //Response.Write("I_ID=" + dr["I_ID"].ToString() + " for deleting");
        }

        #region
        private void InitData()
        {
            dt = TopicManager.ExecuteDataTable("select * from dbo.QS_TOPIC");
        }

        private void TestData()
        {
            dt = new DataTable();
            dt.Columns.Add("I_ID");
            dt.Columns.Add("S_TITLE");
            dt.Columns.Add("S_CREATOR");
            dt.Columns.Add("D_CREATE_DATE");
            dt.Columns.Add("D_END_DATE");

            DataRow dr;

            dr = dt.NewRow();
            dr["I_ID"] = "0";
            dr["S_TITLE"] = "how aaaaaaaa";
            dr["S_CREATOR"] = "aaaaaaa";
            dr["D_CREATE_DATE"] = "1982-2-3 12:00:00";
            dr["D_END_DATE"] = "1982-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "1";
            dr["S_TITLE"] = "how bbbbbbbb";
            dr["S_CREATOR"] = "bbbbbbbb";
            dr["D_CREATE_DATE"] = "1985-2-3 12:00:00";
            dr["D_END_DATE"] = "1985-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "2";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "3";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "4";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "5";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "6";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "7";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "8";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "9";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "10";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "11";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "12";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "13";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["I_ID"] = "14";
            dr["S_TITLE"] = "how ccccccccc";
            dr["S_CREATOR"] = "cccccccccc";
            dr["D_CREATE_DATE"] = "1992-2-3 12:00:00";
            dr["D_END_DATE"] = "1992-2-3 12:00:00";
            dt.Rows.Add(dr);
        }
        #endregion

        protected void lbtn_Add_Click(object sender, EventArgs e)
        {
            Response.Redirect("..\\QS\\TopicDetail.aspx");
        }
    }
    
}